package com.xxchat.controller;

import com.xxchat.annotation.GlobalInterceptor;
import com.xxchat.entity.constants.QueryConstants;
import com.xxchat.entity.dto.TokenUserInfoDTO;
import com.xxchat.entity.po.UserInfo;
import com.xxchat.entity.query.UserInfoQuery;
import com.xxchat.entity.vo.PaginationResultVO;
import com.xxchat.entity.vo.ResponseVO;
import com.xxchat.service.UserInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @author Waicc
 */
@RestController("adminUserInfoController")
@RequestMapping("/admin")
public class AdminUserInfoController extends ABaseController {
    @Resource
    private UserInfoService userInfoService;

    @RequestMapping("/loadUserList")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO loadUserList() {
        UserInfoQuery query = new UserInfoQuery();
        query.setOrderBy(QueryConstants.ORDER_BY_CREATE_TIME_DESC);
        // TODO 传入 pageSize 和 pageNum 自己组装sql
        // TODO 获取列表不能获取自己，获取的数据要过滤敏感信息
        // TODO 搜索功能
        PaginationResultVO<UserInfo> resultVO = this.userInfoService.findListByPage(query);
        return getSuccessResponseVO(resultVO);
    }

    @RequestMapping("/updateUserStatus")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO updateUserStatus(@NotEmpty String userId, @NotNull Integer status) {
        this.userInfoService.updateUserStatusByUserId(userId, status);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/forceOffline")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO forceOffline(@NotEmpty String userId) {
        this.userInfoService.forceOffline(userId);
        return getSuccessResponseVO(null);
    }
}
